#include <iostream>

using std::cout;
using std::endl;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {   cout << "Point(int,int)" << endl;   }

    void print() const
    {
        //私有成员只能在本类内部访问
        cout << "(" << _ix 
             << "," << _iy
             << ")" << endl;
    }

private:
    int _ix;
protected://将其权限开放给派生类内部访问
    int _iy;
};

class Point3D 
: public Point
{
public:
    Point3D(int ix, int iy, int iz)
    : Point(ix, iy)
    , _iz(iz)
    {   cout << "Point3D(int,int,int)" << endl; }

    //新的功能
    void display() const
    {
        //基类私有成员，无法直接访问
        //cout << "_ix:" << _ix << endl; 
        //基类保护成员，在派生类中还是protected的
        cout << "_iy:" << _iy << endl;
        cout << "_iz:" << _iz << endl;
    }
    

private:
    int _iz;
};

int main()
{
    cout << "sizeof(Point):" << sizeof(Point) << endl;
    cout << "sizeof(Point3D):" << sizeof(Point3D) << endl;
    Point3D pt1(1, 2, 3);
    pt1.display();
    //print函数在Point3D中是public成员
    pt1.print();//派生类对象访问, 公有继承基类的公有成员
    //cout << pt1._iy << endl;//error

    return 0;
}

